derive-syn-parse
: A derive macro for syn
's Parse
trait
This is a fairly straightforward derive macro that produces an implementation syn::parse::Parse
for the type it's applied to.
A common pattern when writing custom syn
parsers is repeating <name>: input.parse()?
for
each field in the output. This crate's #[derive(Parse)]
handles that for you, with some helpful
extra customization.
Usage
Using this crate is as simple as adding it to your 'Cargo.toml' and importing the derive macro:
# Cargo.toml
[]
= "0.2.0"
// your_file.rs
use Parse;
The derived implementation of Parse
will always parse in the order that the fields are given.
Detailed information about the various field attributes available is given in the
crate documentation.
This crate is primarily intended for users who are already making heavy use of syn
and wish to
reduce the amount of boilerplate code required.
Motivation
When writing rust code that makes heavy use of syn
's parsing functionality, we often end up
writing things like:
use ;
use ;
// A simplified struct field
//
// x: i32
This is really repetitive! Ideally, we'd like to just #[derive(Parse)]
and have it work. And
so we can! (for the most part) Adding #[derive(Parse)]
to the previous struct produces an
equivalent implementation of Parse
:
use ;
use Parse;
Of course, there are more complicated cases. But - even though they're complicated, many of them are still covered by the various advanced features provided! For more information, see the crate documentation.